package com.sen.common.common.response;

import com.sen.common.common.inter.RespCodeEnum;

/**
 * 全局系统状态码
 *
 * @author esJiang
 */
public enum ResultMsgEnum implements RespCodeEnum, Cloneable {

    // 系统成功码
    SUCCESS(200, "成功", Boolean.TRUE),
    // 系统错误码
    FAILED(400, "系统正忙，请稍后再试", Boolean.FALSE),
    UNAUTHORIZED(401, "没有认证", Boolean.FALSE),
    PAYMENT_REQUIRED(402, "Payment Required", Boolean.FALSE),
    FORBIDDEN(403, "访问被拒绝", Boolean.FALSE),
    NOT_FOUND(404, "Not Found", Boolean.FALSE),
    METHOD_NOT_ALLOWED(405, "Method Not Allowed", Boolean.FALSE),
    NOT_ACCEPTABLE(406, "Not Acceptable", Boolean.FALSE),
    PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required", Boolean.FALSE),
    REQUEST_TIMEOUT(408, "Request Timeout", Boolean.FALSE),
    CONFLICT(409, "Conflict", Boolean.FALSE),
    GONE(410, "Gone", Boolean.FALSE),
    LENGTH_REQUIRED(411, "Length Required", Boolean.FALSE),
    PRECONDITION_FAILED(412, "Precondition Failed", Boolean.FALSE),
    PAYLOAD_TOO_LARGE(413, "Payload Too Large", Boolean.FALSE),
    @Deprecated
    REQUEST_URI_TOO_LONG(414, "Request-URI Too Long", Boolean.FALSE),
    UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type", Boolean.FALSE),
    REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested range not satisfiable", Boolean.FALSE),
    EXPECTATION_FAILED(417, "Expectation Failed", Boolean.FALSE),
    I_AM_A_TEAPOT(418, "I'm a teapot", Boolean.FALSE),
    /**
     * @deprecated
     */
    @Deprecated
    INSUFFICIENT_SPACE_ON_RESOURCE(419, "Insufficient Space On Resource", Boolean.FALSE),
    /**
     * @deprecated
     */
    @Deprecated
    METHOD_FAILURE(420, "Method Failure", Boolean.FALSE),
    /**
     * @deprecated
     */
    @Deprecated
    DESTINATION_LOCKED(421, "Destination Locked", Boolean.FALSE),
    UNPROCESSABLE_ENTITY(422, "Unprocessable Entity", Boolean.FALSE),
    LOCKED(423, "Locked", Boolean.FALSE),
    FAILED_DEPENDENCY(424, "Failed Dependency", Boolean.FALSE),
    TOO_EARLY(425, "Too Early", Boolean.FALSE),
    UPGRADE_REQUIRED(426, "Upgrade Required", Boolean.FALSE),
    PRECONDITION_REQUIRED(428, "Precondition Required", Boolean.FALSE),
    TOO_MANY_REQUESTS(429, "Too Many Requests", Boolean.FALSE),
    bad_credentials(430, "用户名或密码错误", Boolean.FALSE),
    REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large", Boolean.FALSE),
    UNAVAILABLE_FOR_LEGAL_REASONS(451, "Unavailable For Legal Reasons", Boolean.FALSE),
    BAD_CLIENT_Identify(452, "客户端凭证错误", Boolean.FALSE),
    /**
     * 网关异常
     */
    INVALID_TOKEN(453, "token无效", Boolean.FALSE),
    TOKEN_EXPIRED(454, "token过期", Boolean.FALSE),
    /**
     * 系统异常
     */
    SYSTEM_ERROR(500, "系统异常", Boolean.FALSE),
    /**
     * 参数解析异常
     */
    PARSE_PARAM_ERROR(501, "参数解析异常", Boolean.FALSE),
    /**
     * 业务异常
     */
    BIZ_ERROR(502, "业务异常", Boolean.FALSE),
    /**
     * SQL异常
     */
    SQL_ERROR(503, "数据库异常", Boolean.FALSE),
    // 业务错误码
    RECORD_NOT_EXIST(504, "记录不存在", Boolean.FALSE),
    JSON_PARSE_ERROR(505, "JSON解析错误", Boolean.FALSE),
    PARAM_IS_NULL(506, "参数{%s}为空", Boolean.FALSE),
    SERVICE_EXCEPTION(507, "服务异常", Boolean.FALSE),
    tenant_is_progressing(508, "saas正在建设中，暂不支持", Boolean.FALSE),
    enum_is_not_found(509, "找不到枚举信息", Boolean.FALSE),
    delete_not_allow(510, "当前状态不允许删除", Boolean.FALSE),
    ;

    private int code;
    private String message;
    private Boolean success;

    ResultMsgEnum(int value, String text, Boolean success) {
        this.code = value;
        this.message = text;
        this.success = success;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return message;
    }

    @Override
    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public boolean isSuccess() {
        return success;
    }

    @Override
    public RespCodeEnum fillMessage(String field) {
        String format = String.format(this.getMsg(), field);
        RespCodeEnum respCodeEnum = new RespCodeEnum() {

            @Override
            public int getCode() {
                return code;
            }

            @Override
            public String getMsg() {
                return format;
            }

            @Override
            public boolean isSuccess() {
                return success;
            }

        };
        return respCodeEnum;
    }
}